package com.xjt.wx_admin.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.api.R;
import com.xjt.wx_admin.entity.UserApply;
import com.xjt.wx_admin.entity.dto.ApplyUserParam;
import com.xjt.wx_admin.entity.dto.HandleApplyParam;
import com.xjt.wx_admin.service.UserApplyService;
import com.xjt.wx_admin.util.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/userApply")
public class UserApplyController {

    @Autowired
    UserApplyService userApplyService;


    /**
     * 添加好友申请
     *
     * @param applyUserParam 添加好友参数
     * @return {@link R}
     */
    @PostMapping("/applyUser")
    public R applyUser(@RequestBody @Valid ApplyUserParam applyUserParam){
        return userApplyService.applyUser(applyUserParam);
    }


    /**
     * 好友申请处理
     *
     * @param handleApplyParam 好友申请处理参数
     * @return {@link R}
     */
    @PostMapping("/handleApply")
    public R handleApply(@RequestBody @Valid HandleApplyParam handleApplyParam){
        return userApplyService.handleApply(handleApplyParam);
    }


    /**
     * 获取好友申请列表
     *
     * @return {@link R}
     */
    @GetMapping("/getApplyList")
    public R getApplyList(){
        return userApplyService.getApplyList();
    }


    /**
     * 获取好友申请列表
     *
     * @return {@link R}
     */
    @GetMapping("/getWaitHandleCount")
    public R getWaitHandleCount(){
        int count = userApplyService.count(Wrappers.<UserApply>lambdaQuery()
                .eq(UserApply::getApplyId, SecurityUtils.getUserId())
                .eq(UserApply::getState,0)
        );
        return R.ok(count);
    }


}
